<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/9/24
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>学生展示</title>
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" >
</head>
<body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
<%--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="importExcel">批量导入excel数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="addStu">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">是否全选</button>
    </div>
</script>

<div class="layui-btn-container" id="upddiv" style="display: none">
    <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
    <button type="button" class="layui-btn" id="test9">开始上传</button>
</div>
<form class="layui-form" action=""  id="saveUserForm" style="display: none"  lay-filter="updateUserFormFilter">
    <input type="hidden" name="id" >

    <form class="layui-form" action="" >

        <div class="registerbox-title">用户注册中心</div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户账号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" onblur="checkUsername(this)"  lay-verify="required" placeholder="请输入账号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

            <div class="layui-form-item pass" >
                <label class="layui-form-label">用户密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password"  lay-verify="required" placeholder="请输入密码" autocomplete="off"
                           class="layui-input" id="pass1">
                </div>
            </div>
            <div class="layui-form-item pass" >
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password"  lay-verify="required|pass" placeholder="请再次输入密码"
                           autocomplete="off" class="layui-input" id="pass2">
                </div>
            </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男" checked="">
                <input type="radio" name="sex" value="女" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <select name="rid"  class="layui-select ridSelect">
<%--                    <option value="">请选择...</option>--%>
<%--                    <option value="2">员工</option>--%>
<%--                    <option value="1">管理员</option>--%>
                </select>
            </div>
        </div>


        <%--状态--%>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="hidden"  id="status" name="status"/>
                <input type="checkbox" name="statusswitch" checked  lay-skin="switch" lay-filter="switchStatus" lay-text="启用|禁用">
            </div>
        </div>

        <%--开关   选中的时候 on   未选中的时候 off  一般不用开关传值   on 1  off 2--%>


        <div class="layui-form-item">
            <div class="layui-upload" style="margin-left: 90px">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list" style="margin:10px -3px;">

                    <img class="layui-upload-img"
                         width="100px" height="100px" style="border-radius: 50%" id="demo1" src="${pageContext.request.contextPath}/static/img/a.jpg">
                    <p id="demoText"></p>
                </div>
                <!--上传返回的图片地址-->
                <input type="hidden" name="imgpath" id="uploadImg" value="">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSaveUser">注册</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>


<%----%>


    <%--查询条件--%>
    <form class="layui-form" action="">

        <div class="layui-inline">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status"  class="layui-select">
                    <option value="">请选择...</option>
                    <option value="1">启用</option>
                    <option value="2">禁用</option>
                </select>
            </div>

        </div>

        <div class="layui-inline">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <select name="rid"   class="layui-select ridSelect">
                    <option value="">请选择...</option>
<%--                    <option value="1">启用</option>--%>
<%--                    <option value="2">禁用</option>--%>
                </select>
            </div>

        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
<table class="layui-hide" id="test" lay-filter = "test"></table>
<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<script>

        layui.use(['table','layer','form','jquery'], function(){
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
         var upload = layui.upload
                ,element = layui.element

            table.render({
                // element  元素
                elem: '#test'
                ,page:true
                ,limit:10
                ,limits:[10,20,30,40]
                ,toolbar: '#toolbarDemo'
                ,url:'${pageContext.request.contextPath}/tFpaSub' //  表格了里面所需要的数据就是一个list里面有很多的map、对象
                ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    // field 后面跟的内容  必须跟后台传过来的数据里面的map 的key保持一致
                    ,{field:'fpano', title: '编号', sort: true}
                    ,{field:'fpasub', title: '题目'} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
                    ,{field:'xxa', title: '选项A', sort: true}
                    ,{field:'xxb', title: '选项B', sort: true}
                    ,{field:'xxc', title: '选项C', sort: true}
                    ,{field:'xxd', title: '选项D', sort: true}
                    ,{fixed: 'right', title:'操作', width: 125, minWidth: 125, toolbar: '#barDemo'}
                ]]

            });


            // 查询
            form.on('submit(formDemo)', function(data){
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                table.reload('test', {
                    where: data.field,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

            // // 自定义校验  验证两次密码是不是一样
            form.verify({
                pass: function(value){ //自定义lay-verify的昵称，value：表单的值
                    var pass1 = $("#pass1").val();
                    if(value!=pass1){
                        return "两次密码不一致！！！";
                    }

                }
            });


            // 工具栏事件
            table.on('toolbar(test)', function(obj){
                var uid = obj.config.uid;
                var checkStatus = table.checkStatus(uid);
                var othis = lay(this);
                switch(obj.event){
                    case 'importExcel':

                        layer.open({
                            type: 1,
                            area: ['500px', '400px'],
                            offset: '100px',
                            content:$("#upddiv"),
                            cancel: function(index, layero){

                                layer.close(index);
                                $("#upddiv").hide();
                                return false;
                            }

                        });
                        //选完文件后不自动上传
                        upload.render({
                            elem: '#test8'
                            ,url: '${pageContext.request.contextPath}/tFpaSub/import' //此处配置你自己的上传接口即可
                            ,auto: false// 不自动上传
                            ,accept:"file" // 允许上传所有的文件
                            //,multiple: true
                            ,bindAction: '#test9' // 绑定上传的按钮
                            ,done: function(res){
                                if(res.data==true){
                                    layer.msg("导入数据成功",{"icon":1});
                                    $("#upddiv").hide();
                                    layer.closeAll();
                                }
                            }
                        });
                        // 上传excel让后台解析

                        // excel文档在远端
                        <%--$.ajax({--%>
                        <%--    url:"${pageContext.request.contextPath}/tFpaSub/import",--%>
                        <%--    type:"post",--%>
                        <%--    success:function(res){--%>
                        <%--        if(res.data==true){--%>
                        <%--            layer.msg("导入数据成功",{"icon":1});--%>
                        <%--        }--%>
                        <%--    }--%>
                        <%--})--%>
                        break;
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(layui.util.escape(JSON.stringify(data)));
                        break;
                    case 'getData':
                        var getData = table.getData(id);
                        console.log(getData);
                        layer.alert(layui.util.escape(JSON.stringify(getData)));
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选')
                        break;

                };
            });

            //触发单元格工具事件
            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'edit'){


                }
            });

    })

</script>

</body>
</html>
